<?php

namespace Common\Model;

use Think\Model;

class patientNormalCureModel extends Model {

    protected $tableName = 'patient_normal_cure';

    protected $_validate = array(
        ['car_id', 'require', 'car_id 需要提供', self::MUST_VALIDATE],
        ['patient_id', 'require', 'patient_id 需要提供', self::MUST_VALIDATE],
        ['method_id', 'require', 'method_id 需要提供', self::MUST_VALIDATE],
    );

    protected $_auto = array(
        ['create_time', 'time', self::MODEL_INSERT, 'function'],
    );

    /**
     * 对病人添加一般治疗手段
     */
    public function addNormalCure($carId, $patientId, $methodIdList) {
        $data = [];

        //删除之前的数据
        $this->where(['car_id' => $carId, 'patient_id' => $patient_id])->delete();

        $methodArr = json_decode($methodIdList, true);
        foreach ($methodArr as $methodId) {
            $data = [
                'car_id' => $carId,
                'patient_id' => $patientId,
                'method_id' => $methodId
            ];
            if (!$this->create($data)) {
                return ['status' => 0, 'error_info' => $this->getError()];
            }
            $this->add();
        }

        return ['status' => 1];

    }

    public function getAllInfo($patient){
        return $this->where(['patient_id'=>$patient])->select();
    }
}